package com.wangc.report.utils;

import org.apache.poi.xssf.usermodel.*;

import java.io.FileOutputStream;

/**
 * java掉用excle示例
 */
public class ExportExcel {

    public static void main(String[] args) {
        try {
            new ExportExcel().export();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void export() throws Exception {
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet("0");
        //  创建行
        for (int i = 0; i < 50000; i++) {
            XSSFRow row = sheet.createRow(i);

            XSSFCell cell = row.createCell(0);
            cell.setCellValue(i);
            XSSFCell cell21 = row.createCell(1);
            cell21.setCellValue(new XSSFRichTextString("|"));

            XSSFCell cell2 = row.createCell(2);
            cell2.setCellValue(new XSSFRichTextString("Hello!"));
            XSSFCell cell22 = row.createCell(3);
            cell22.setCellValue(new XSSFRichTextString("|"));

            XSSFCell cell3 = row.createCell(4);
            cell3.setCellValue(new XSSFRichTextString("100.00"));
            XSSFCell cell23 = row.createCell(5);
            cell23.setCellValue(new XSSFRichTextString("|"));

            XSSFCell cell4 = row.createCell(6);
            cell4.setCellValue(new XSSFRichTextString("100.00"));
            XSSFCell cell24 = row.createCell(7);
            cell24.setCellValue(new XSSFRichTextString("|"));

        }
        System.out.println("over");
        //  写文件
        FileOutputStream fos = new FileOutputStream("init\\test.xlsx");
        wb.write(fos);
        fos.close();
    }
}
